package com.wowangz.cms.systemmanage.parameter.service;

import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.systemmanage.parameter.pojo.Parameter;

public class ParameterService extends BaseService {

	private Logger logger = LoggerFactory.getLogger(ParameterService.class);
	
	/**
	 * 分页查询总条数
	 * 
	 */
	public long findResultCount(HashMap<String, Object> map) throws ServiceException {
		try {
			Long countNum = this.getSqlSession().selectOne("Parameter.queryParameterCount", map);
			return countNum;
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}			
	}

	/**
	 * 查询记录集合
	 * 
	 */
	public List<Parameter> findResultList(HashMap<String, Object> map) throws ServiceException {
		try {
			List<Parameter> list = this.getSqlSession().selectList("Parameter.queryParameterPage", map);
			return list;
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}		
	}
	
	/**
	 * 验证信息
	 */
	public boolean validationParameter(HashMap<String, Object> map) throws ServiceException {
		try {
			Long countNum = this.getSqlSession().selectOne("Parameter.validationParameter", map);
			if(countNum != 0){
				return false;
			}else{
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}		
	}
	
	/**
	 * 新增系统参数
	 *
	 */
	public void addParameter(Parameter parameter) throws ServiceException {
		try {
			this.getSqlSession().insert("Parameter.insertParameter", parameter);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}		
	}
	
	/**
	 * 根据ID查询系统参数
	 *
	 */
	public Parameter findParameterById(String id) throws ServiceException {
		try {
			Parameter parameter = this.getSqlSession().selectOne("Parameter.findParameterById", id);
			return parameter;
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}			
	}
	
	/**
	 * 修改系统参数
	 *
	 */
	public void updateParameter(Parameter parameter) throws ServiceException {
		try {
			this.getSqlSession().update("Parameter.updateParameter", parameter);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}	
	}
	
	
}
